/**
*      author: Y_Yao
*      created: 2025-02-22 12:21:14
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
int n;
unordered_map<int,int> mp;

int f(int x)
{
    if(x == 1) return 0;
    if(mp.count(x)) return mp[x];
    else return mp[x] = f(x / 2) + f((x + 1) / 2) + x;
}

void solve()
{
    cin >> n;
    cout << f(n) << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}